<template>
  <div class="popularTours">
    <div class="header">
      <div class="left">
        <div class="title">热门巡演</div>
        <van-image :src="popularTours.subImage" class="iconHotTour"></van-image>
      </div>
      <div class="right" @click="goToTourList"><van-icon name="arrow" size="20" /></div>
    </div>
    <div class="list">
      <ul class="tour-list">
        <li
          class="tour-list-item"
          v-for="tour in popularTours.rooms[0].items"
          :key="tour.id"
          @click="goToTourDetail(tour.id)"
        >
          <div class="thumb-container">
            <img class="thumb" :src="tour.imgUrl" />
            <!-- <van-image :src="tour.imgUrl" fit="cover"></van-image> -->
            <div class="show-tag">
              <van-rolling-text
                :text-list="formatRollTagList(tour.rollTagList)"
                direction="up"
                :duration="1"
              />
            </div>
          </div>
          <div class="tour-title">
            {{ tour.title }}
          </div>
        </li>
      </ul>
    </div>
  </div>
</template>

<script setup>
import { toRefs } from 'vue'
import { useRouter } from 'vue-router'
const router = useRouter()

const props = defineProps({
  popularTours: Object,
})

const { popularTours } = toRefs(props)

//格式化处理翻滚的tags方法
const formatRollTagList = (rollTagList) => {
  let tags = rollTagList.map((tagItem) => {
    // 返回一个字符串： tagItem.rollTagStatusName+' '+tagItem.rollTagCityName
    return tagItem.rollTagStatusName + ' ' + tagItem.rollTagCityName
  })

  // console.log('tags', tags)
  return tags
}

// 进入巡演简介页面
const goToTourDetail = (id) => {
  router.push({ path: '/show-tour-detail', query: { tourId: id } })
}

const goToTourList = () => {
  router.push({ path: '/tour-list' })
}
</script>

<style scoped lang="scss">
.popularTours {
  margin-top: 20px;

  .header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    font-size: 18px;
    color: #000;
    font-weight: 600;

    .left {
      display: flex;
      align-items: center;

      .title {
        margin-right: 10px;
      }

      .iconHotTour {
        width: 50px;
      }
    }
  }

  .list {
    margin-top: 10px;

    ul.tour-list {
      list-style: none;
      display: flex;
      align-items: flex-start;
      justify-content: flex-start;
      overflow-x: auto;
      gap: 10px;

      scrollbar-width: none;
      /* Firefox */
      -ms-overflow-style: none;
      /* IE 10+ */

      &::-webkit-scrollbar {
        display: none;
        /* Chrome Safari */
      }

      li.tour-list-item {
        display: flex;
        flex-direction: column;

        .thumb-container {
          position: relative;
          overflow: hidden;
          width: 120px;
          height: 160px;

          .thumb {
            width: 100%;
            height: 100%;
            border-radius: 10px;
          }

          .show-tag {
            position: absolute;
            left: 0;
            bottom: 5px;
          }
        }

        .tour-title {
          display: -webkit-box; // 使用弹性盒子布局
          -webkit-line-clamp: 2; // 限制显示2行
          -webkit-box-orient: vertical; // 垂直排列
          overflow: hidden; // 超出部分隐藏
          text-overflow: ellipsis; // 超出部分用省略号表示
          font-size: 16px;
          font-weight: 500;
          width: 120px;
          word-wrap: break-word; // 允许长单词换行
          margin-top: 5px;
        }
      }
    }
  }
}
</style>
